# PowerShell脚本 - 环境设置

param(
    [string]$MCPApiKey = "",
    [string]$JianYingPath = "C:\\Program Files\\JianyingPro"
)

Write-Host "🚀 开始设置Python4Video环境..." -ForegroundColor Green

# 检查Python版本
$pythonVersion = python --version
if ($LASTEXITCODE -ne 0) {
    Write-Host "❌ 未找到Python，请先安装Python 3.8+" -ForegroundColor Red
    exit 1
}
Write-Host "✅ Python版本: $pythonVersion" -ForegroundColor Green

# 检查uv
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
    Write-Host "📥 安装uv..." -ForegroundColor Yellow
    pip install uv
}

# 安装项目依赖
Write-Host "📦 安装项目依赖..." -ForegroundColor Yellow
uv sync

# 创建必要的目录
$directories = @("temp", "output", "logs")
foreach ($dir in $directories) {
    if (-not (Test-Path $dir)) {
        New-Item -ItemType Directory -Path $dir -Force | Out-Null
        Write-Host "✅ 创建目录: $dir" -ForegroundColor Green
    }
}

# 更新配置文件
if ($MCPApiKey) {
    Write-Host "🔧 更新配置文件..." -ForegroundColor Yellow
    $configContent = Get-Content "config.yaml" -Raw
    $configContent = $configContent -replace "your_mcp_api_key_here", $MCPApiKey
    
    if ($JianYingPath -ne "C:\\Program Files\\JianyingPro") {
        $configContent = $configContent -replace "C:\\\\Program Files\\\\JianyingPro", $JianYingPath
    }
    
    Set-Content "config.yaml" -Value $configContent
    Write-Host "✅ 配置文件已更新" -ForegroundColor Green
}

# 检查剪映安装
if (Test-Path $JianYingPath) {
    Write-Host "✅ 剪映专业版已安装: $JianYingPath" -ForegroundColor Green
} else {
    Write-Host "⚠️  未找到剪映专业版，请确认安装路径: $JianYingPath" -ForegroundColor Yellow
}

Write-Host ""
Write-Host "🎉 环境设置完成！" -ForegroundColor Green
Write-Host ""
Write-Host "下一步操作:" -ForegroundColor White
Write-Host "1. 编辑 config.yaml 文件配置您的API密钥" -ForegroundColor White
Write-Host "2. 运行示例: python examples/basic_usage.py" -ForegroundColor White
Write-Host "3. 或使用命令行: python -m python4video.cli.main generate --text '您的文案'" -ForegroundColor White